package practice_0527;

public class practice02 {
    public static void main(String[] args) {
        deadLock deadLock = new deadLock(true);
        deadLock deadLock2 = new deadLock(false);
        deadLock.start();
        deadLock2.start();

    }
}

class deadLock extends Thread {
    public boolean flag;
    static Object obj1 = new Object();
    static Object obj2 = new Object();

    public deadLock(boolean flag) {
        this.flag = flag;
    }

    @Override
    public void run() {
        if (flag) {
            synchronized (obj1) {
                System.out.println(Thread.currentThread().getName() + "进入1");
                synchronized (obj2) {
                    System.out.println(Thread.currentThread().getName() + "进入2");
                }
            }
        } else {
            synchronized (obj2) {
                System.out.println(Thread.currentThread().getName() + "进入3");
                synchronized (obj1) {
                    System.out.println(Thread.currentThread().getName() + "进入4");
                }
            }
        }
    }
}